#!/usr/bin/env php
<?php
include_once(dirname(__FILE__).'/config.php');
include_once(dirname(__FILE__).'/utilities.php');

$store = ARC2::getStore($arc_config);

$time = time();

$q = <<<EOT
PREFIX vocabs: <http://desanti.org/schemas/vocabularies#>
SELECT * WHERE {
    ?c a vocabs:Class .
}
EOT;
$rs = $store->query($q);
if(!$store->getErrors()){
	$rows = $rs['result']['rows'];
    foreach($rows as $row){
        $time += 1;
        $c = label($row,'c');
        $newC = 'http://desanti.org/classes/'.$time;
        $q = <<<EOT
SELECT * WHERE {
    $c ?p ?o .
}
EOT;
        $rs = $store->query($q);
        if(!$store->getErrors()){
            $rows = $rs['result']['rows'];
            foreach($rows as $row){
                $p = label($row,'p');
                $o = label($row,'o');
                $q = <<<EOT
DELETE {
    $c $p $o .
}
EOT;
                query($q, $store);
                $q = <<<EOT
INSERT INTO <http://desanti.org/> {
    <$newC> $p $o .
}
EOT;
                query($q, $store);
            }
        }
        $q = <<<EOT
SELECT * WHERE {
    ?s ?p $c .
}
EOT;
        $rs = $store->query($q);
        if(!$store->getErrors()){
            $rows = $rs['result']['rows'];
            foreach($rows as $row){
                $p = label($row,'p');
                $s = label($row,'s');
                $q = <<<EOT
DELETE {
    $s $p $c .
}
EOT;
                query($q, $store);
                $q = <<<EOT
INSERT INTO <http://desanti.org/> {
    $s $p <$newC> .
}
EOT;
                query($q, $store);
            }
        }
    }
}

?>
